{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "\n",
    "a = Symbol(\"a\")\n",
    "x1 = Symbol(\"x1\")\n",
    "x2 = Symbol(\"x2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{cases}\n",
    "x_1 + a x_2 = 1\\\\\n",
    "a x_1 + x_2 = 0\\\\\n",
    "\\end{cases}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "e = [\n",
    "    x1 + a * x2 - 1,\n",
    "    a * x1 + x2,\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a=0.99\n",
      "x2: -49.7487437185929\n",
      "x1: 50.2512562814070\n",
      "---\n",
      "a=0.991\n",
      "x2: -55.3044254701713\n",
      "x1: 55.8066856409397\n",
      "---\n"
     ]
    }
   ],
   "source": [
    "r = solve(e, [x1, x2])\n",
    "\n",
    "for n in [0.99, 0.991]:\n",
    "    print(f\"a={n}\")\n",
    "    for k in r:\n",
    "        print(f\"{k}: {r[k].subs(a, n)}\")\n",
    "    print(\"---\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{cases}\n",
    "x_1 + a x_2 = 1\\\\\n",
    "a x_1 + 4x_2 = 0\\\\\n",
    "\\end{cases}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a=0.99\n",
      "x2: -0.327825424682937\n",
      "x1: 1.32454717043611\n",
      "---\n",
      "a=0.991\n",
      "x2: -0.328371967571032\n",
      "x1: 1.32541661986289\n",
      "---\n"
     ]
    }
   ],
   "source": [
    "e = [\n",
    "    x1 + a * x2 - 1,\n",
    "    a * x1 + 4 * x2,\n",
    "]\n",
    "\n",
    "r = solve(e, [x1, x2])\n",
    "\n",
    "for n in [0.99, 0.991]:\n",
    "    print(f\"a={n}\")\n",
    "    for k in r:\n",
    "        print(f\"{k}: {r[k].subs(a, n)}\")\n",
    "    print(\"---\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
